﻿using System;
using System.Data;
using System.Collections.Generic;

namespace CounterServerModel
{
    /// <summary>
    /// A class that represents a fault.
    /// </summary>
    public class Fault
    {
        /// <summary>
        /// The ID of the fault.
        /// </summary>
        public int FaultID { get; set; }

        /// <summary>
        /// The ID of the user created the fault.
        /// </summary>
        public int UserID { get; set; }

        /// <summary>
        /// The ID of the Account with the problem.
        /// </summary>
        public int AccountID { get; set; }

        /// <summary>
        /// The date on which the fault occured.
        /// </summary>
        public DateTime FaultDate { get; set; }

        /// <summary>
        /// The description of the fault.
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// Determines whether the fault is solved.
        /// </summary>
        public bool IsSolved { get; set; }

        public Fault(int i_FaultID, int i_UserID)
        {
            FaultID = i_FaultID;
            UserID = i_UserID;
        }

        public Fault() { }

        /// <summary>
        /// Creates a fault based on the given DataRow.
        /// </summary>
        /// <param name="i_DataRow">The DataRow to create the fault from.</param>
        /// <returns>A fault based on the given DataRow.</returns>
        public static Fault CreateFromFaultRow(DataRow i_DataRow)
        {
            Fault fault = new Fault(int.Parse(i_DataRow["FaultID"].ToString()), int.Parse(i_DataRow["UserID"].ToString()));
            fault.AccountID = int.Parse(i_DataRow["AccountID"].ToString());
            fault.FaultDate = DateTime.Parse(i_DataRow["FaultDate"].ToString());
            fault.Description = i_DataRow["Description"].ToString();
            fault.IsSolved = bool.Parse(i_DataRow["IsSolved"].ToString());

            return fault;
        }
    }
}
